﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RedDragon.Common.Domain.Manufacture;
using RedDragon.Common.Dtos;
using RedDragon.ERP.API.Application.Commands.BoM;
using RedDragon.ERP.API.Application.Commands.Resource;
using RedDragon.ERP.API.Application.Commands.WorkCenter;
using T.Common.Domain.Common;

namespace RedDragon.ERP.API.Controllers
{
    /// <summary>
    /// 工作中心控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkCenterController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public WorkCenterController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 工作中心添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> CreateWorkCenter(CreateWorkCenterCommand cmd)
        {
            cmd.CreatedTime = DateTime.Now;
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 工作中心列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<PageResultDto<WorkCenters>>> QueryWorkCenter(QueryWorkCenterCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 工作中心删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<Result> DeleteWorkCenter(DeleteWorkCenterCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 根据工作id获取工作信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> GetWorkCenter(GetWorkCenterCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 修改工作中心
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> UpdateWorkCenter(UpdateWorkCenterCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 审批工作中心
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> UpdApproveState(UpdApproveStateCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 工作中心导入
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> ImportWorkCenter(ImportWorkCenterCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 根据工作编码获取工作信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> Get2WorkCenter(Get2WorkCenterCommand cmd)
        {
            return await mediator.Send(cmd);
        }
    }
}

